package com.zhaoxi.project.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.wms.domain.WmsGoodsStockCheck;
import com.zhaoxi.project.wms.service.impl.WmsGoodsStockCheckServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 仓储盘点Controller
 *
 * @author zhaoxi
 * @date 2023-08-25
 */
@RestController
@RequestMapping("/wms/stockCheck")
public class WmsGoodsStockCheckController extends BaseController {
    @Autowired
    private WmsGoodsStockCheckServiceImpl wmsGoodsStockCheckService;

    /**
     * 查询仓储盘点列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stockCheck:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsGoodsStockCheck wmsGoodsStockCheck) {
        startPage();
        List<WmsGoodsStockCheck> list = wmsGoodsStockCheckService.selectWmsGoodsStockCheckList(wmsGoodsStockCheck);
        return getDataTable(list);
    }

    /**
     * 导出仓储盘点列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stockCheck:export')")
    @Log(title = "仓储盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsGoodsStockCheck wmsGoodsStockCheck) {
        List<WmsGoodsStockCheck> list = wmsGoodsStockCheckService.selectWmsGoodsStockCheckList(wmsGoodsStockCheck);
        ExcelUtil<WmsGoodsStockCheck> util = new ExcelUtil<WmsGoodsStockCheck>(WmsGoodsStockCheck.class);
        util.exportExcel(response, list, "仓储盘点数据");
    }

    /**
     * 获取仓储盘点详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:stockCheck:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wmsGoodsStockCheckService.selectWmsGoodsStockCheckById(id));
    }

    /**
     * 新增仓储盘点
     */
    @PreAuthorize("@ss.hasPermi('wms:stockCheck:add')")
    @Log(title = "仓储盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsGoodsStockCheck wmsGoodsStockCheck) {
        return toAjax(wmsGoodsStockCheckService.insertWmsGoodsStockCheck(wmsGoodsStockCheck));
    }

    /**
     * 修改仓储盘点
     */
    @PreAuthorize("@ss.hasPermi('wms:stockCheck:edit')")
    @Log(title = "仓储盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsGoodsStockCheck wmsGoodsStockCheck) {
        return toAjax(wmsGoodsStockCheckService.updateWmsGoodsStockCheck(wmsGoodsStockCheck));
    }

    /**
     * 删除仓储盘点
     */
    @PreAuthorize("@ss.hasPermi('wms:stockCheck:remove')")
    @Log(title = "仓储盘点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wmsGoodsStockCheckService.deleteWmsGoodsStockCheckByIds(ids));
    }
}
